import Vue from 'vue'
import Vuex from 'vuex'
import modules from "./modules"
 //vuex 持久化
import createPersistedState from "vuex-persistedstate"
Vue.use(Vuex);

 // 配置需要缓存的vuex
const cacheVuex = {
    admin:['tags','menuIndex','showMenu'],
    user:['permissions','pageLoading','userInfo'],
}
function getCacheVuex(val){
    let obj = {}
    Object.keys(cacheVuex).forEach(item=>{
        obj[item] = {}
        cacheVuex[item].forEach(_item=>{
            obj[item][_item] = val[item][_item]
        })
    })
    return obj
}
export default new Vuex.Store({
    plugins: [createPersistedState({ //缓存指定vuex
        storage:window.localStorage, //定义缓存方式  
        reducer:(val)=>{
            return getCacheVuex(val)
        }
    })],  
    state: {

    },
    mutations: {
        //
    },
    actions: {
        //
    },
    modules: {
        ...modules
    }
})